package me.joshua.demo4j.java.web.sample;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

/**
 * A servlet say hello
 */
public class Hello extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		name = StringUtils.trimToNull(name);
		if (null == name) {
			name = "world";
		}
		request.setAttribute("name", name);
		request.getRequestDispatcher("hello.jsp").forward(request, response);
	}

}
